import json


class JsonEditor:
    def __init__(self, filename, encoding='utf-8'):
        self.filename = filename
        self.encoding = encoding
        with open(filename, mode='r', encoding=encoding) as fp:
            data = fp.read()
        if data == '':
            self.json_data = {}  # type: dict
        else:
            self.json_data = json.loads(data)  # type: dict

    def setItem(self, key, value):
        self.json_data[key] = value
        with open(self.filename, mode='w', encoding=self.encoding) as fp:
            fp.write(self.dumps(self.json_data))

    def get(self, key):
        return self.json_data.get(key, None)

    def dumps(self, obj) -> str:
        return json.dumps(obj, indent=4, ensure_ascii=False)
